// ToolCamera.cpp: implementation of the ToolCamera class.
//
//////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "FXTool.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9.h>
#include <D3D9.h>


#include "ToolCamera.h"
#include <object.h>
#include <D3DAppForm.h>
#include "ToolApp.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define		K			2.5
extern ToolApp *g_Draw;

ToolCamera::ToolCamera()
{
	howFar=15.0f;
	D3DXMatrixRotationY(&rotmat,3.141592*180/180);
	D3DXMatrixIdentity(&mTrans);
	isrotate=FALSE;
	camove=FALSE;
	camheight=10;
	isFirst=FALSE;
}

ToolCamera::~ToolCamera()
{
}

int ToolCamera::ObjProc(int hMsg, unsigned long wParam, unsigned long lParam)
{
	static int oldz=0;
	static float eyey=0.0f;
	static int camz=0;
	D3DXMATRIX *rot;
	D3DXMATRIX *pos;
	D3DXMATRIX temp;
	D3DXVECTOR3 oldtrans;
	int refresh=0;
	switch(hMsg)
	{
	case OM_TIMER:
		D3DXVECTOR3 at;
		at.x=0;
		at.y=8;
		at.z=0;

		eye.x=0;
		eye.y=0;
		eye.z=howFar*1.4f;
		D3DXMatrixIdentity(&temp);
		temp._41=eye.x;
		temp._42=eye.y;
		temp._43=eye.z;
		D3DXMATRIX height;
		D3DXMatrixRotationX(&height,-D3DXToRadian(camheight));
		at.y+=(float)(camheight-40)/10.0f;
		temp=temp*height;

		temp=temp*rotmat;
		eye.x=temp._41;
		eye.y=temp._42;
		eye.z=temp._43;

		eye=at+eye;
		D3DXVECTOR3 up(0,1,0);
		D3DXMatrixLookAtLH(&mTrans,&eye,&at,&up);
		g_Draw->m_pd3dDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&mTrans);
		CAM::GetActiveCam()->m_matView = mTrans;
		g_Draw->m_pd3dDevice->GetTransform(D3DTS_PROJECTION,&CAM::GetActiveCam()->m_matProj);

		break;
	}
	return TRUE;
}

